﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DotNetX
{
    /// <summary>
    /// A list of all supported languages
    /// </summary>
    public class Languages
    {
        /// <summary>
        /// The supported languages
        /// </summary>
        public static List<Language> AllLanguages
        {
            get
            {
                // return the languages
                return _languages;
            }
        }
        #region Languages

        private static List<Language> _languages = new List<Language>(
            new Language[] {
                new Language("Afar", "AA", "Unknown"),
                new Language("Abkhazian", "AB", "Unknown"),
                new Language("Afrikaans", "AF", "Unknown"),
                new Language("Amharic", "AM", "Unknown"),
                new Language("Arabic", "AR", "Unknown"),
                new Language("Assamese", "AS", "Unknown"),
                new Language("Aymara", "AY", "Unknown"),
                new Language("Azerbaijani", "AZ", "Unknown"),
                new Language("Bashkir", "BA", "Unknown"),
                new Language("Byelorussian", "BE", "Unknown"),
                new Language("Bulgarian", "BG", "Unknown"),
                new Language("Bihari", "BH", "Unknown"),
                new Language("Bislama", "BI", "Unknown"),
                new Language("Bengali", "BN", "Unknown"),
                new Language("Bangla", "BN", "Unknown"),
                new Language("Tibetan", "BO", "Unknown"),
                new Language("Breton", "BR", "Unknown"),
                new Language("Catalan", "CA", "Unknown"),
                new Language("Chinese (Traditional)", "CH", "China"),
                new Language("Chinese (Traditional)", "CH", "Taiwan"),
                new Language("Chinese (Simplified)", "CHS", "China"),
                new Language("Corsican", "CO", "Unknown"),
                new Language("Czech", "CS", "Unknown"),
                new Language("Welsh", "CY", "Unknown"),
                new Language("Danish", "DA", "Unknown"),
                new Language("German", "DE", "Unknown"),
                new Language("Bhutani", "DZ", "Unknown"),
                new Language("Greek", "EL", "Unknown"),
                new Language("English", "EN", "England"),
                new Language("English", "EN", "Australia"),
                new Language("American", "EN", "America"),
                new Language("Esperanto", "EO", "Unknown"),
                new Language("Spanish", "ES", "Spain"),
                new Language("Estonian", "ET", "Unknown"),
                new Language("Basque", "EU", "Unknown"),
                new Language("Persian", "FA", "Unknown"),
                new Language("Finnish", "FI", "Unknown"),
                new Language("Fiji", "FJ", "Unknown"),
                new Language("Faeroese", "FO", "Unknown"),
                new Language("French", "FR", "France"),
                new Language("Frisian", "FY", "Unknown"),
                new Language("Irish", "GA", "Ireland"),
                new Language("Gaelic", "GD", "Unknown"),
                new Language("Galician", "GL", "Unknown"),
                new Language("Guarani", "GN", "Unknown"),
                new Language("Gujarati", "GU", "Unknown"),
                new Language("Hausa", "HA", "Unknown"),
                new Language("Hindi", "HI", "Unknown"),
                new Language("Croatian", "HR", "Unknown"),
                new Language("Hungarian", "HU", "Unknown"),
                new Language("Armenian", "HY", "Unknown"),
                new Language("Interlingua", "IA", "Unknown"),
                new Language("Interlingue", "IE", "Unknown"),
                new Language("Inupiak", "IK", "Unknown"),
                new Language("Indonesian", "IN", "Unknown"),
                new Language("Icelandic", "IS", "Unknown"),
                new Language("Italian", "IT", "Unknown"),
                new Language("Hebrew", "IW", "Unknown"),
                new Language("Japanese", "JA", "Japan"),
                new Language("Yiddish", "JI", "Unknown"),
                new Language("Javanese", "JW", "Unknown"),
                new Language("Georgian", "KA", "Unknown"),
                new Language("Kazakh", "KK", "Unknown"),
                new Language("Greenlandic", "KL", "Unknown"),
                new Language("Cambodian", "KM", "Unknown"),
                new Language("Kannada", "KN", "Unknown"),
                new Language("Korean", "KO", "Unknown"),
                new Language("Kashmiri", "KS", "Unknown"),
                new Language("Kurdish", "KU", "Unknown"),
                new Language("Kirghiz", "KY", "Unknown"),
                new Language("Latin", "LA", "Unknown"),
                new Language("Lingala", "LN", "Unknown"),
                new Language("Laothian", "LO", "Unknown"),
                new Language("Lithuanian", "LT", "Unknown"),
                new Language("Latvian", "LV", "Unknown"),
                new Language("Lettish", "LV", "Unknown"),
                new Language("Malagasy", "MG", "Unknown"),
                new Language("Maori", "MI", "Unknown"),
                new Language("Macedonian", "MK", "Unknown"),
                new Language("Malayalam", "ML", "Unknown"),
                new Language("Mongolian", "MN", "Unknown"),
                new Language("Moldavian", "MO", "Unknown"),
                new Language("Marathi", "MR", "Unknown"),
                new Language("Malay", "MS", "Unknown"),
                new Language("Maltese", "MT", "Unknown"),
                new Language("Burmese", "MY", "Unknown"),
                new Language("Nauru", "NA", "Unknown"),
                new Language("Nepali", "NE", "Unknown"),
                new Language("Dutch", "NL", "Unknown"),
                new Language("Norwegian", "NO", "Unknown"),
                new Language("Occitan", "OC", "Unknown"),
                new Language("Oromo", "OM", "Unknown"),
                new Language("Afan", "OM", "Unknown"),
                new Language("Oriya", "OR", "Unknown"),
                new Language("Punjabi", "PA", "Unknown"),
                new Language("Polish", "PL", "Unknown"),
                new Language("Pashto", "PS", "Unknown"),
                new Language("Pushto", "PS", "Unknown"),
                new Language("Portuguese", "PT", "Unknown"),
                new Language("Quechua", "QU", "Unknown"),
                new Language("Rhaeto-Romance", "RM", "Unknown"),
                new Language("Kirundi", "RN", "Unknown"),
                new Language("Romanian", "RO", "Unknown"),
                new Language("Russian", "RU", "Unknown"),
                new Language("Kinyarwanda", "RW", "Unknown"),
                new Language("Sanskrit", "SA", "Unknown"),
                new Language("Sindhi", "SD", "Unknown"),
                new Language("Sangro", "SG", "Unknown"),
                new Language("Serbo-Croatian", "SH", "Unknown"),
                new Language("Singhalese", "SI", "Unknown"),
                new Language("Slovak", "SK", "Unknown"),
                new Language("Slovenian", "SL", "Unknown"),
                new Language("Samoan", "SM", "Unknown"),
                new Language("Shona", "SN", "Unknown"),
                new Language("Somali", "SO", "Unknown"),
                new Language("Albanian", "SQ", "Unknown"),
                new Language("Serbian", "SR", "Unknown"),
                new Language("Siswati", "SS", "Unknown"),
                new Language("Sesotho", "ST", "Unknown"),
                new Language("Sudanese", "SU", "Unknown"),
                new Language("Swedish", "SV", "Unknown"),
                new Language("Swahili", "SW", "Unknown"),
                new Language("Tamil", "TA", "Unknown"),
                new Language("Tegulu", "TE", "Unknown"),
                new Language("Tajik", "TG", "Unknown"),
                new Language("Thai", "TH", "Unknown"),
                new Language("Tigrinya", "TI", "Unknown"),
                new Language("Turkmen", "TK", "Unknown"),
                new Language("Tagalog", "TL", "Unknown"),
                new Language("Setswana", "TN", "Unknown"),
                new Language("Tonga", "TO", "Unknown"),
                new Language("Turkish", "TR", "Unknown"),
                new Language("Tsonga", "TS", "Unknown"),
                new Language("Tatar", "TT", "Unknown"),
                new Language("Twi", "TW", "Unknown"),
                new Language("Ukrainian", "UK", "Ukrain"),
                new Language("Urdu", "UR", "Unknown"),
                new Language("Uzbek", "UZ", "Unknown"),
                new Language("Vietnamese", "VI", "Unknown"),
                new Language("Volapuk", "VO", "Unknown"),
                new Language("Wolof", "WO", "Unknown"),
                new Language("Xhosa", "XH", "Unknown"),
                new Language("Yoruba", "YO", "Unknown"),
                new Language("Zulu", "ZU", "Unknown") });

        #endregion

        /// <summary>
        /// This returns all languages by thier name
        /// </summary>
        /// <param name="name">The name of the language</param>
        /// <returns>The languages that match the passed name</returns>
        public static List<Language> GetByName(string name)
        {
            if (name == null)
                throw new ArgumentNullException("'name' is null.");
            if (name.Length == 0)
                throw new ArgumentOutOfRangeException("'name' is zero-length.");

            // trim the name
            name = name.Trim();

            // return the languages
            return (from l in AllLanguages
                    where l.CountryName.Trim().StartsWith(name)
                    select l).ToList();
        }

        /// <summary>
        /// This returns all languages by their code
        /// </summary>
        /// <param name="code">The code</param>
        /// <returns>The languages that match the passed code</returns>
        public static List<Language> GetByCode(string code)
        {
            if (code == null)
                throw new ArgumentNullException("'code' is null.");
            if (code.Length == 0)
                throw new ArgumentOutOfRangeException("'code' is zero-length.");

            // trim the code
            code = code.Trim();

            // return the languages
            return (from l in AllLanguages
                    where l.Code.Trim().StartsWith(code)
                    select l).ToList();
        }
    }
}
